<template>
    <div class="frame">
            <el-dialog
            :title='this.$t("et.transferOut")+coinName'
            :visible.sync="showOut"
            width="440px"
            :before-close="closeFrame"
            >  
            <div class="content ">
                <div class="content-title">{{$t("et.transferOut")}}{{coinName}}</div>
                <div class="content-copy">
                    <span>{{this.ethDetail.address}}</span>
                    <img src="../../assets/images/copy.png" alt=""
                          v-clipboard:copy="this.ethDetail.address"
                          v-clipboard:success="onCopy"
                          v-clipboard:error="onError" >
                </div>
                <div class="content-input">
                    <div class="model">
                        <div class="model-top flex">
                            <div>ETH</div>
                            <div style="flex:1"></div>
                            <div>{{$t("et.balance")}}：
                              <span v-if="this.ethDetail.balance">{{this.ethDetail.balance}}</span>
                              <span v-else>0</span>
                              ETH
                            </div>
                        </div>
                        <div class="model-bottom flex">
                            <input type="text" :placeholder="this.$t('et.transferAmountPlaceholder')" v-model="outform.amount">
                            <div style="flex:1"></div>
                            <div>ETH</div>
                        </div>
                    </div>
                    <div class="model">
                        <div class="model-top flex">
                            <div>{{$t("et.receiptAddress")}}</div>
                        </div>
                        <div class="model-bottom flex">
                            <input type="text" :placeholder="this.$t('et.receiptAddressPlaceholder')" v-model="outform.to" >
                        </div>
                    </div>
                    <div v-if="!state" class="model">
                        <div class="model-top flex">
                            <div>{{$t("et.gas")}}</div>
                            <div style="flex:1"></div>
                            <div>0.00031 ether ≈ ￥0.36</div>
                        </div>
                        <div class="model-bottom flex">
                            <input type="text" v-model="outform.gasprice" :placeholder="this.$t('et.gas2')">
                            <div style="flex:1"></div>
                            <div>{{coinName}}</div>
                        </div>
                        <div class="model-bottom2">
                            <input type="text"  :placeholder="this.$t('et.gas1')" v-model="outform.gaslimit">
                        </div>
                    </div>
                    <div v-else class="model">
                        <div class="model-top flex">
                            <div>{{$t("et.gas")}}</div>
                            <div style="flex:1"></div>
                            <div>0.00031 ether ≈ ￥0.36</div>
                        </div>
                        <div class="model-slider">
                            <div class="block" style="width:100%">
                                <!-- <span class="demonstration">自定义初始值</span> -->
                                <el-slider v-model="outform.gasprice" ></el-slider>
                            </div>
                            <div class="speed flex">
                                <div class="speed-left">Slow</div>
                                <div class="speed-cen">{{outform.gasprice}} gwei</div>
                                <div class="speed-right">Fast</div>
                            </div>

                        </div>

                    </div>
                    <div class="custom flex" @click="switchMedia">
                        <div v-if="state" class="switch flex">
                            <div class="switch-one"></div>
                              <div class="switch-two"></div>
                        </div>
                        <div v-else class="switch switch2 flex">
                            <div class="switch-two"></div>
                            <div class="switch-one"></div>

                        </div>
                        <p>{{$t("et.gasSet")}}</p>
                    </div>
                    
                </div>

                <div class="content-button"><button @click="outEth">{$t("et.transferOut")}}</button></div>
            </div>
        </el-dialog>
    </div>
</template>
<script>
  import {sendTrx} from '../../service/ethService'
export default{
    data(){
        return{
             showOut:true,
             state:true,
             value: 0,
             coinName:'ETH',
             ethDetail: '',
             outform:{
               form :'',
               to:'0xDaBBbacFF575a85E47EA1D1ff97f55B22Ab3184A' ,
               // secret:'cm710068',
               amount:0.001,
               gasprice:5,
               gaslimit:35000,
             }
        }
    },
  created(){
    this.ethDetail = JSON.parse(window.sessionStorage.getItem("ethWalletDetail"));
  },
   methods:{
        // 转入
        closeFrame(){
           this.$emit('outethListen',false)
        },

        //   自定义矿工费切换
        switchMedia(){
         this.state=!this.state
        },

        // 复制成功
        onCopy(){
            this.$message({
                message: '复制成功',
                type: 'success'
                });
        },
        
        // 复制失败
        onError(){
            this.$message({
                message: '复制失败',
                type: 'erro'
                });
        },
         outEth(){
          if(this.ethDetail.balance>this.outform.amount){
            this.outform.address='';
            this.outform.address=this.ethDetail.address;
              if(this.outform.gasprice<5){
                this.$message.warning(
                  '手续费过低，交易时间会延长'
                )
            }
            this.$emit('outethListen',false,true,this.outform)
          }else {
            this.$message.warning(
              '余额不足'
            )
            this.$emit('outethListen',false)
          }

       }
         
    } 
}
 
</script>
<style lang="less" scoped>
.frame{
    .el-dialog__wrapper{     
        .el-dialog{
             border-radius: 8px;
        }
        .el-dialog__header{
            border-bottom:1px solid #eaedf5;
            color:#000000;
            font-size: 18px;
            font-weight: bold;
            padding:20px;
        }
        .el-dialog__body{
            padding:30px 0;
        }
        .el-dialog__headerbtn .el-dialog__close{
            color: #666666;
           
        }
     }
  }
.content{
     .content-title{
         text-align: center;
         color: #98889b;
         font-size: 18px;
     }
     .content-copy{
          font-size: 12px;
          color: #666666;
          text-align: center;
          cursor: pointer;
         img{
             width:12px;
             height:14px;
             margin-bottom: -3px;
         }
     }
      .content-code{
           margin: 20px 0;
           padding: 20px 0;
           height: 262px;
           background-color: #fbfbfc;
           div{
               width: 178px;
               height: 178px;
               margin: 0 auto;
               img{
                   width: 100%;
               }
           }
           p{
               margin: 10px;
               color: #666666; 
              text-align: center;
           }
      }
      .content-input{
          padding: 10px 20px;
          margin-top: 20px;
          background:#fbfbfc;; 
          color: #666666;
          input{
            width: 349px;
            height: 34px;
            padding: 0 10px;
            border-radius: 4px;
            border: solid 1px #eeeeee;
            background-color: #ffffff; 
          }
          input::-webkit-input-placeholder {
            font-size: 12px;
            color: #c5c7cb;
          
         }
          .balance{
            margin-bottom: 15px;  
          }
          .transfer{
              padding-bottom: 20px;
              border-bottom: 1px solid #eaedf5;
              div{
                 line-height: 34px;
              }
          }
          .memo{
              padding-top: 20px 
          }
          .adress{
             margin-bottom: 15px;   
          }
          .model{
              border-bottom:1px solid #eaedf5;
              padding: 10px 0 20px;
              &-top{
                  margin-bottom: 15px;   
              }
              &-bottom{
                  line-height: 34px;
              }
              &-bottom2{
                margin: 10px 0;  
              }
              &-slider{
                //   width: 400px;
                  margin: 0px 10px;
                  .speed{
                     font-size: 10px;
                     div{
                         width: 33.3%;
                        //  display: inline-block;/
                     } 
                     &-cen{
                         font-weight: bold;
                         text-align: center;
                     }
                     &-right{
                         text-align: right;
                     }
                     
                  }
              }
          }
          .custom{
             padding: 20px 0;
             font-size: 10px;
             color: #98889b;  
             flex-direction: row-reverse;
             p{
                 padding:  0 10px;
             }
             .switch{
                 background: #fff;
                 padding: 3px 0;
                 cursor: pointer;
                 &-one{
                     width: 10px;
                     height: 10px;
                     border-radius: 50%;
                     border: 1px solid #e1e5e9;
                 }
                 &-two{
                     width: 20px;
                     height: 2px;
                     background: #e1e5e9;
                     margin: 4px 0;
                 }
              }
             .switch2{
                 div{
                    background: #908093
                 }
                
             }
          }
      }
      .content-button{ 
         margin: 22px 0;
        button{
            color:#fff;
            width: 400px;
            margin:  0 auto;
            display: block;
            border-radius: 4px;
            line-height:32px;
            text-align: center;
            background-color: #98889b;
            outline: none;
            border: none;
            cursor: pointer;
        }
        button:hover{
            opacity: .8;
        }   
      }
}
.flex{
    display: flex;
}
</style>
<style lang="less" >
.el-slider__bar{
    background-color: #98889b;
}
.el-slider__button{
  border:#98889b;
 background-color: #98889b;

}
.frame{
  .el-dialog__wrapper{
    .el-dialog{
      border-radius: 8px;
    }
    .el-dialog__header{
      border-bottom:1px solid #eaedf5;
      color:#000000;
      font-size: 18px;
      font-weight: bold;
      padding:20px;
    }
    .el-dialog__body{
      padding:30px 0;
    }
    .el-dialog__headerbtn .el-dialog__close{
      color: #666666;

    }
  }
}
</style>


